/**
 *  Copyright 2006-2007 EmbedChat
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.embedchat.desktop.gui;

import java.util.HashMap;
import java.util.Map;

import javax.swing.AbstractListModel;
import javax.swing.MutableComboBoxModel;

public class RoomListComboModel extends AbstractListModel implements MutableComboBoxModel {
	
	private static final long serialVersionUID = -2145941750845772766L;
	
	private Map<Integer, String> map = new HashMap<Integer, String>();
	private Object selected;

	public Object getSelectedItem() {
		return selected;
	}

	public void setSelectedItem(Object item) {
		if((selected != null && ! selected.equals(item)) || (selected == null && item != null)) {
			selected = item;
			fireContentsChanged(this, -1, -1);
		}
	}

	public int getSize() {
		return map.size();
	}

	public Object getElementAt(int index) {
		return map.get(index);
	}

	public void addElement(Object obj) {
		map.put(map.size(), obj.toString());
	}

	public void removeElement(Object obj) {
		map.remove(obj);
	}

	public void insertElementAt(Object obj, int index) {
		map.put(index, obj.toString());
	}

	public void removeElementAt(int index) {
	}
}
